package com.caine.tool;

public class StringTool {

    /**
     * 是否是null或者""(空)
     *
     * @param obj
     * @return
     */
    public static boolean isNullOrEmpty(Object obj) {
        if (obj == null) return true;
        if (obj.toString().trim().equals("") || obj.toString().trim().length() == 0) return true;
        return false;
    }

    public static boolean isNullOrEmpty(Object... objs) {
        if (objs == null) return true;
        if (objs.length == 0) return true;
        for (Object obj : objs) {
            if (!isNullOrEmpty(obj)) {
                return true;
            }
        }
        return false;
    }

    public static boolean isBlank(CharSequence cs) {
        if (cs != null) {
            int length = cs.length();
            for (int i = 0; i < length; i++) {
                if (!Character.isWhitespace(cs.charAt(i))) {
                    return false;
                }
            }
        }
        return true;
    }

    /**
     * 对象转为字符串去除左右空格
     *
     * @param o 带转换对象
     * @return
     */
    public static String toStrinIdGeneratorgTrim(Object o) {
        return String.valueOf(o).trim();
    }

    /**
     * @see #isBlank(CharSequence)
     */
    public static boolean isNotBlank(CharSequence cs) {
        return !isBlank(cs);
    }

    public static String fillData(String val, int len, String fillVal) {
        for (int i = len - val.length(); i > 0; i--) {
            val = fillVal + val;
        }
        return val;
    }
}
